﻿@using SCMS.Resources
@model SCMS.UI.Models.RegisterAsset
@using SCMS.CoreBusinessLogic.Settings
@{
    AjaxOptions ajaxOpts;
    if (ViewBag.CurrentItem == ViewBag.TotalItems)
    {
        ajaxOpts = new AjaxOptions
        {
            UpdateTargetId = "AssetsDiv",
            LoadingElementId = "loading",
            HttpMethod = "Post",
            Url = Url.Action("RegsiterItem/" + ViewBag.GRNItemId),
            OnSuccess = "javascript:CloseDialog()",
            //OnFailure = "javascript:errormsg()"
        };
    }
    else
    {
        ajaxOpts = new AjaxOptions
        {
            UpdateTargetId = "popup-page",
            LoadingElementId = "popup-loading",
            HttpMethod = "Post",
            Url = Url.Action("RegsiterItem/" + ViewBag.GRNItemId),
            OnSuccess = "clearAssetForm();CenterPopup();"

        };
    }}
<input type="hidden" value="@ViewBag.CurrentItem" id="currentItem" />
<input type="hidden" value="@ViewBag.TotalItems" id="totalItems" />
<script src="@Url.Content("~/Scripts/js/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/js/jquery.autocomplete.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/js/general.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

@using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form", enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(true)
    <div>
        <span class="details"><strong>@Resources_frank.Global_String_Item &nbsp; @ViewBag.CurrentItem &nbsp; @Resources_frank.Global_String_Of &nbsp; @ViewBag.TotalItems
            &nbsp;</strong> </span>
    </div>
    <table width="600" align="center" cellpadding="2">
        <tr class="gridheader2">
            <td align="center" width="33.3%">
                @Resources_frank.Budget_CategoryList_ProjectNo
            </td>
            <td align="center" width="33.3%">
                @Resources_morgan.Global_String_AssetNo
            </td>
            <td align="center" width="33.3%">
                @Resources_morgan.Global_String_SerialNo
            </td>
        </tr>
        <tr>
            <td align="center" valign="top">
                @ViewBag.CurrentProject
                @Html.HiddenFor(x => x.EntityAsset.CurrentProjectDonorId)
                @Html.HiddenFor(x => x.EntityAsset.DepreciationCurrencyId)
            </td>
            <td align="center" valign="top">
                @Html.TextBoxFor(x => x.EntityAsset.AssetNumber, new { @readonly = "readonly", id = "refNo" })
                @Html.ValidationMessageFor(x => x.EntityAsset.AssetNumber, Resources_frank.Global_String_Required)
            </td>
            <td align="center" valign="top">
                @Html.EditorFor(x => x.EntityAsset.SerialNumber)
                @Html.ValidationMessageFor(x => x.EntityAsset.SerialNumber, Resources_frank.Global_String_Required)
            </td>
        </tr>
        <tr class="gridheader2">
            <td align="center" width="33.3%">
                @Resources_morgan.Global_String_ItemName
            </td>
            <td align="center" width="33.3%">
                @Resources_frank.Global_String_AssetDescription
            </td>
            <td align="center" width="33.3%">
                @Resources_morgan.Global_String_Weight
            </td>
        </tr>
        <tr>
            <td align="center" valign="top">
                @ViewBag.ItemName
            </td>
            <td align="center" valign="top">
                @Html.TextAreaFor(x => x.EntityAsset.Name, new { id = "AssetDessc", name = "AssetDessc" })
                @Html.ValidationMessageFor(x => x.EntityAsset.Name, Resources_frank.Global_String_Required)
                <script type="text/javascript">
                    var $jq = jQuery.noConflict();
                    $jq("#AssetDessc").autocomplete("/GoodsReceivedNote/SearchAssetDesc");
                </script>
            </td>
            <td align="center" valign="top">
                @Html.TextBoxFor(x => x.EntityAsset.Weight, new { id = "txtweight", @class = "numericTb" })
                @Html.ValidationMessageFor(x => x.EntityAsset.Weight, Resources_frank.Global_String_Required)
            </td>
        </tr>
        <tr class="gridheader2">
            <td align="center" width="33.3%">
                @Resources_frank.GoodsReceivedNote_LoadOtherAssets_PurchasePrice (@ViewBag.Currency)
            </td>
            <td align="center" width="33.3%">
                @Resources_frank.Global_String_EstLifespan
            </td>
            <td align="center" width="33.3%">
                @Resources_frank.Global_String_UseEstLifespan
            </td>
        </tr>
        <tr>
            <td align="center" valign="top">
                @Html.TextBoxFor(x => x.EntityAsset.PurchaseValue, new { @disabled = "disabled", @class = "numericTb", id = "purcahseValue" })
                @Html.ValidationMessageFor(x => x.EntityAsset.PurchaseValue, Resources_frank.Global_String_Required)
            </td>
            <td align="center" valign="top">
                @Html.TextBoxFor(x => x.EntityAsset.Lifespan)
                @Html.ValidationMessageFor(x => x.EntityAsset.Lifespan, Resources_frank.Global_String_Required)
            </td>
            <td align="center" valign="top">
                @Html.CheckBoxFor(x => x.EntityAsset.UseLifeSpan)
            </td>
        </tr>
        <tr class="gridheader2">
            <td align="center" width="33.3%">
                @Resources_frank.GoodsReceivedNote_LoadOtherAssets_DepreciationType
            </td>
            <td align="center" width="33.3%">
                @Resources_frank.GoodsReceivedNote_LoadOtherAssets_PercentageDep
            </td>
            <td align="center" width="33.3%">
                @Resources_frank.GoodsReceivedNote_GRAssetList_SalvageValue
            </td>
        </tr>
        <tr>
            <td align="center" valign="top">
                @Html.DropDownListFor(x => x.EntityAsset.DepreciationType, new SelectList(
                new List<Object>{ 
                    new { value = "Straight Line" , text = Resources_frank.Global_DepreciationType_StraightLine  },
                    new { value = "Reducing Balance" , text = Resources_frank.Global_DepreciationType_ReducingBalance },
                    new { value = "Zero Balance" , text = Resources_frank.Global_DepreciationType_ZeroBalance}
                }, "value", "text"), Resources_frank.Global_String_PleaseSelect)
                @Html.ValidationMessageFor(x => x.EntityAsset.DepreciationType)
            </td>
            <td align="center" valign="top">
                @Html.TextBoxFor(x => x.EntityAsset.PercentageDepr)
                @Html.ValidationMessageFor(x => x.EntityAsset.PercentageDepr, Resources_frank.Global_String_Required)
            </td>
            <td align="center" valign="top">
                @Html.TextBoxFor(x => x.EntityAsset.SalvageValue, new { id = "txtsalvageValue", @class = "numericTb", onblur = "javascript:ValidateSalvageValue(this);" })
                @Html.ValidationMessageFor(x => x.EntityAsset.SalvageValue, Resources_frank.Global_String_Required)
            </td>
        </tr>
        <tr class="gridheader2">
            <td align="center" width="33.3%">
                @Resources_frank.GoodsReceivedNote_LoadRegisterAsset_OpeningAccDep
            </td>
            <td align="center" width="33.3%">
                @Resources_morgan.Global_String_Warehouse
            </td>
            <td align="center" width="33.3%">
                @Resources_frank.GoodsReceivedNote_LoadOtherAssets_IsFleet
            </td>
        </tr>
        <tr>
            <td align="center" valign="top">
                @Html.TextBoxFor(x => x.EntityAsset.OpeningAccDepreciaiton, new { @class = "numericTb" })
                @Html.ValidationMessageFor(x => x.EntityAsset.OpeningAccDepreciaiton, Resources_frank.Global_String_Required)
            </td>
            <td align="center" valign="top">
                @Html.DropDownListFor(x => x.EntityAsset.CurrentWareHouseId, Model.Warehouses, Resources_frank.Global_String_PleaseSelect)
                @Html.ValidationMessageFor(x => x.EntityAsset.CurrentWareHouseId, Resources_frank.Global_String_Required)
            </td>
            <td align="center" valign="top">@Html.EditorFor(x => x.EntityAsset.IsFleet)
                @Html.ValidationMessageFor(x => x.EntityAsset.IsFleet, "Required")
            </td>
        </tr>
        <tr>
            <td align="center" width="33.3%">
            </td>
            <td align="center" width="33.3%">
                <input type="submit" class="btn green" value="@Resources_frank.GoodsReceivedNote_LoadGRAssetItems_RegisterAsset" />
            </td>
            <td align="right">
            </td>
        </tr>
    </table>
    <hr />
}